﻿package bonus {
	
	import field.Ball;
	import field.Element;
	import field.NormalBomb;
	import flash.display.MovieClip;
	
	
	public class AtomicBomb extends Bonus {
		
		
		public function AtomicBomb() {
			// constructor code
		}
		
		public override function apply(): void {			
			for (var i: Number = 0; i < main.panel.numChildren; i++) {
				if (main.panel.getChildAt(i) is Element){
					if (main.panel.elementsUnderCursor[ Element(main.panel.getChildAt(i)) ] != undefined) {
						var bomb: field.AtomicBomb = new field.AtomicBomb();
						bomb.tileX = Element(main.panel.getChildAt(i)).tileX;
						bomb.tileY = Element(main.panel.getChildAt(i)).tileY;
						bomb.x = Element(main.panel.getChildAt(i)).x;
						bomb.y = Element(main.panel.getChildAt(i)).y;
						main.panel.elementsUnderCursor[ main.panel.elements[bomb.tileY][bomb.tileX] ] = bomb;
						main.panel.elements[bomb.tileY][bomb.tileX] = bomb;
						main.panel.removeChildAt(i);
						main.panel.addChild(bomb);
					}
				}
			}
			
			super.apply();
		}
		
		public override function select(tileX: Number, tileY: Number): void {
			var element: Element = main.panel.elements[tileY][tileX];
			main.panel.elementsUnderCursor [element] = element;
			
			main.panel.blinkElementsUnderCursor();
		}
		
	}
	
}
